//
//  SWBookChooseCell.swift
//  Fff
//
//  Created by linhan on 16/3/28.
//  Copyright © 2016年 MiU. All rights reserved.
//

import Foundation
import UIKit
class SWBookChooseCell: UITableViewCell
{
    weak var book:SWBook?
    private var _cellWidth:CGFloat = 0
    
    lazy private var _imageView:UIImageView = UIImageView()
    lazy private var _nameLabel:UILabel = UILabel()
    lazy private var _countLabel:UILabel = UILabel()
    
    init(style: UITableViewCellStyle, reuseIdentifier: String?, cellWidth:CGFloat)
    {
        _cellWidth = cellWidth
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        setup()
    }
    
    required init(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setup()
    {
        let countLabelWidth:CGFloat = 100
        _countLabel.font = UIFont.systemFont(ofSize: 14)
        _countLabel.frame = CGRectMake(_cellWidth - countLabelWidth, 10, countLabelWidth, 18)
        _countLabel.textAlignment = .right
        contentView.addSubview(_countLabel)
        
        let NameLabelX:CGFloat = 20
        let NameLabelRightMargin:CGFloat = 30
        let NameLabelHeight:CGFloat = 19
        _nameLabel.font = UIFont.systemFont(ofSize: 15)
        _nameLabel.textColor = UIColor(hex: 0xAAAAAA)
        _nameLabel.frame = CGRectMake(NameLabelX, (SWThemeStyle.BookCellHeight - NameLabelHeight) * 0.5, _cellWidth - NameLabelRightMargin - NameLabelX, NameLabelHeight)
        contentView.addSubview(_nameLabel)
        
        
    }
    
    override func layoutSubviews()
    {
        super.layoutSubviews()
        
        if let book = book
        {
            _nameLabel.text = book.title
            
            let count:Int = SWTransactionManager.sharedManager().pages.filter({($0.page.bookID ?? "") == (book.bookID ?? "")}).count
            _countLabel.text = "数量：\(count)"
        }
    }
    
    
    
    
}
